package com.mall.manager.service;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.mall.common.attributes.CommonAttributes;
import com.mall.common.dao.MongoDBManager;
import com.mall.untils.DateUtils;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

@Service
public class BabySingleService {
	
	Logger logger = Logger.getLogger(BabyTopService.class);
	
	/**
	 * 根据类型和当天时间查询宝宝单题关联信息
	 * @param type SDK,HTML,PC
	 * @param collection mongodb表
	 * @param dtype 数据类型
	 * @return
	 */
	public List<DBObject> findMongodb(String type,String collection,String dtype){
		logger.info("查询mongodb表："+collection+"；数据来源类型："+type+"；数据类型："+dtype);
		//当前日期的前一天
		String beforDate = DateUtils.getNowBeforDay();
		
		BasicDBList list = new BasicDBList();
		//按时间检索前一天的数据
		BasicDBObject dbo = new BasicDBObject();
		dbo.append("commit_time", new BasicDBObject("$gte", beforDate+" 00:00:00"));
		dbo.append("commit_time", new BasicDBObject("$lte", beforDate+" 23:59:59"));
		//数据类型查询
		BasicDBObject db = new BasicDBObject();
		db.append("data_type", CommonAttributes.getMap(dtype));
		list.add(dbo);
		list.add(db);
		BasicDBObject d = new BasicDBObject();
		d.put("$and", list);
		
		return MongoDBManager.findForCommitTime(collection, d);
	}
}
